<?php

namespace App\Console\Commands;

use App\Handlers\KeysHandler;
use App\Jobs\CheckActivation;
use App\Jobs\PeriodDrawJob;
use App\Jobs\PeriodWinJob;
use App\Models\Account;
use App\Models\Api;
use App\Models\Fund;
use App\Models\FundPeriod;
use App\Models\FundOrder;
use App\Models\FundPlay;
use App\Models\Goods;
use App\Models\Order;
use App\Models\Phone;
use App\Models\User;
use App\Models\PointLog;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use App\Services\TronService;
use IEXBase\TronAPI\Exception\TronException;
use IEXBase\TronAPI\Provider\HttpProvider;
use IEXBase\TronAPI\Tron;
use danielme85\Geoip2\Facade\Reader;

class CeshiCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'ceshi';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '测试';


    private array $data = [];

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }
    public function getBaseNameByUrl($url) {
        $arr = parse_url($url);
        $arr2 = pathinfo($arr['path']);
        return $arr2;
    }
    public function handle()
    {

        $goods = Goods::all();
        foreach ($goods as $good){
            $arr = self::getBaseNameByUrl($good->img);
            $good->img = $arr['dirname']. '/'.urlencode($arr['filename']) .'.'.$arr['extension'];
            $good->save();
        }


        /*
        $this->line('开始'.date('Y-m-d H:i:s'));
        for($i=1;$i<=100000;$i++){
            $data = [
                'api_id' => rand(4,24),
                'phone'  => rand(10000000000,999999999999999)
            ];
            $api = Api::getApi($data['api_id']);
            if($api){
                Phone::firstOrCreate([
                    'phone' => $data['phone']
                ],[
                    'api_id' => $data['api_id'],
                    'type' => $api->type,
                    'datenum' => date('Ymd',time())
                ]);
            }
        }
        $this->line('结束'.date('Y-m-d H:i:s'));
*/


    }




}
